<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<%@ include file="/common/import.jsp" %>
<script>
  var thsTitle = "专组管理";
  var objName="session";
  var currentObjId = "";
</script>
<script type="text/javascript" src="${ctx}/js/zbxupload.js"></script> 
<title>专组管理-${sysName }</title>
</head>
<body class="home-template">
<!-- 正文开始 -->
<div class="searchForm"><form id="myList_form">
	<input type="hidden" name="page"  value="1">
	<input type="hidden" name="rows"  value="7">
	<input type="hidden" name="sessionType" id="sessionType" value="3">
	专组名称：<input type="text" name="sessionName"  value="" /> 
	<a class="easyui-linkbutton"  iconCls="icon-search" onclick="myListSearch();">查询</a>
	<a class="easyui-linkbutton"  onclick="clearFormById('myList_form');">清空</a>
	<a class="easyui-linkbutton"  iconCls="icon-add" onclick="addOPen();">增加新的专组</a>
</form></div>
<table id="myList_table" class="info" cellspacing="1" cellpadding="0">
	<tr class='active' id="title2" >
		<th width='30%'>专组名称</th>
		<th width='10%'>竞价方式</th>
		<th width='10%'>状态</th>	
		<th width='30%'>创建时间</th>		
		<th width='15%' class='th_center'>操作</th>
	</tr>
</table>
<div id="myList_page" class="page"></div>
<script type="text/template" id="myList_html">
	<? for ( var i = 0; i < rows.length; i++) {?>
		<tr id=bill_<?=rows[i].billid?>>
			<td title=<?=rows[i].sessionName?>><?=strUtil.subStr(rows[i].sessionName,25)?></td>
			<td style="text-align:center;"><?=bidModeText(rows[i].sessionMode)?></td>
			<td style="text-align:center;"><?=sessionStatusText(rows[i].status)?></td>
			<td style="text-align:center;"><?=rows[i].createTime?></td>
			<td>
				<a class="mybutton"  onclick="view('<?=rows[i].sessionId?>');">专组管理</a> 
                <?if(rows[i].status==0 ){?>
				|| <a class="mybutton"  onclick="del('<?=rows[i].sessionId?>');">删除</a>
				<?}?>
			</td>
		</tr>
   <?}?>  		
</script>
<!-- 正文结束 -->
<%@ include file="/common/top.jsp" %>
<div class="easyui-dialog" id="add_window" title="增加专组" closed="true" modal="true" style="width:900px;height:550px;">
<form id="addForm" onsubmit="">
<table class="info" cellspacing="1" cellpadding="0">
	<input type="hidden" name="sessionId" id="sessionId" value="">
	<input type="hidden" name="sessionType" value="3">
	<input type="hidden" name="status" id="status" value="0">
	<input type="hidden" name="orgEname" value="${loginUser.orgEname}">
	<input type="hidden" name="orgCname" value="${loginUser.orgCname}">
	<input type="hidden" name="direction" value="">
	<input type="hidden" name="bailCtrl" value="1">
	<input type="hidden" name="bailFix" value="0">
	
	<tr>
		<th>专组名称：<font color="red">*</font></th>

		<td colspan="3"><input type="text" name="sessionName" id="sessionName" class="easyui-validatebox validatebox-text" 
			validtype="length[1,66]"	required="true"  missingMessage="请输入专组名称"  maxlength="66"
				invalidMessage="最多可输入66中文字符"  title="最多可输入66中文字符"  size="80" value=""/>
		</td>

	</tr>
	<tr>
		<th>是否动态报价：<font color="red">*</font></th>
		<td colspan="3">
			<input type="radio" name="ifBidDyn"  value="F" checked onclick="setIfBidDynCtr('F')"/>网络竞价 
			<input type="radio" name="ifBidDyn"  value="T"  onclick="setIfBidDynCtr('T')"/>动态报价 &nbsp;&nbsp;
			
		</td>
		<!-- <th>是否串行：<font color="red">*</font></th>
		<td >
			<input type="radio" name="serialCtrl"  value="F" checked onclick="line('F')"/>否 &nbsp;&nbsp;
			<input type="radio" name="serialCtrl"  value="T" onclick="line('T')"/>是 （前一个标的结束后下一个标的才开始）
		</td> -->
	</tr>
	<tr>
		<th>竞价方式：<font color="red">*</font></th>
		<td><input type="text" name="sessionMode" id="sessionMode"  /></td>
		<th>是否分组开始：<font color="red">*</font></th>
		<td >
			<input type="radio" name="ifGroup"  value="T"  />分组&nbsp;
			<input type="radio" name="ifGroup"  value="F" checked />不分组&nbsp;
		</td>
	</tr>
	<tr>
	    <th>报价服务器：<font color="red">*</font></th>
		<td><select  id="bjServerStr" name="bjServerStr" /></select></td>
		<th>专组图片：</th>
		<td>
		<div msg="第1组">
		  <img id="fileUpText_1_showImg" src="${ctx}/images/def.jpg" style="height:40px;" />
		  <label onclick="addUploadFile(1);" for="uploadFileInput" class="fDef_Btn" >选择文件</label>
		  <label id="fileUpText_1_subbtn" onclick="$.zbxupload.uploadSubmit(this);" style='display:none;' class="fDef_Btnse" >开始上传</label>
		  <input id="fileUpText_1" name="picUrl" type="hidden" class="fDef_Input" > <!-- 此元素的name="attaUrl" 对照修改后台属性，以备入库 -->
		</div>
         </td>
	</tr>
	<tr>
	   <th>竞价开始时间：<font color="red">*</font></th>
		<td colspan="3"><input type="hidden" name="openTime" id="openTime" value=""  /> 
				<select id="openTime_y" class="myDate"></select>年
				<select id="openTime_m" class="myDate"></select>月
				<select id="openTime_d" class="myDate"></select>日
				<select id="openTime_hh" class="myTime"></select>时
				<select id="openTime_mm" class="myTime"></select>分
				<select id="openTime_ss" class="myTime"></select>秒
		
		</td>
	</tr>
	<tr id="tr_zybjq" >
		<th>自由报价期：<font color="red">*</font></th>
		<td colspan="3"><input type="text" name="firstTime"  id="firstTime"  value="60" size="10" maxlength="4" validtype="number"  class="easyui-validatebox validatebox-text" 
				   invalidMessage="必须为1~4位长的非负数字"  title="自由报价期"/>[<font id="firstTimeTxt">分钟</font>] </td>
	</tr>
	<tr id="limitTimeTr">
		<th>限时报价周期：<font color="red">*</font></th>
		<td colspan="3"><input type="text" name="limitTime" id="limitTime"  value="60" size="10" maxlength="4" validtype="number"  class="easyui-validatebox validatebox-text" 
			   invalidMessage="必须为1~4位长的非负数字"  title="限时报价周期"  onblur="if(this.value=='') {this.value='60';}"  />（秒）</td>
	</tr>
	<tr id="tr_xxsc" style="display:none;">
		<th>休息时长：<font color="red">*</font></th>
		<td colspan="3"><input type="text" name="restTime"  id="restTime"  value="5" size="10" maxlength="4" validtype="number" class="easyui-validatebox validatebox-text" 
		 invalidMessage="必须为1~4位长的非负数字"  title="休息时长" />（分钟） </td>
	</tr>
	<tr>
		<th>专组介绍：<font color="red">*</font></th>
		<td colspan="3"><textarea cols=80 rows=4 id="infoDesc" name="infoDesc" maxlength="110"  class="easyui-validatebox validatebox-text" 
			validtype="length[1,100]"	required="true"  missingMessage="请输入专组介绍"  
				invalidMessage="最多可输入100中文字符"  title="最多可输入100中文字符" ></textarea></td>
	</tr>
	<tr>
		<td colspan="4" style="text-align:center;">
			<a class="easyui-linkbutton" id="addButton" iconCls="icon-add" onclick="add();">增加</a>
			<a class="easyui-linkbutton" id="editButton" iconCls="icon-add" onclick="edit();">修改</a>
		</td>
	</tr>
</table>
</form>
</div>

<!-- 附件上传iframe元素 -->
<iframe name='uploadIframe' id='uploadIframe' frameborder='0' height='0' width='0'></iframe>
<div id="uploadIframeDefDiv" style="height:0px;" ></div>

</body>
</html>

<script>
function setIfBidDynCtr(flag){
	if("T"==flag){
		//动态报价,不允许串行控制，并且设置否
		/* $("#addForm").find("input[name='serialCtrl']").each(function(){
          $(this).attr("disabled","disabled");
        });
		ZBXTools.initRadio("serialCtrl","F"); */
		$("#firstTime").val('5');
		$("#firstTimeTxt").html('天');
	}else{
		//网络竞价，允许串行控制
		/* $("#addForm").find("input[name='serialCtrl']").each(function(){
         $(this).attr("disabled",false);
        }); */
		$("#firstTime").val('60');
		$("#firstTimeTxt").html('分钟');
	}
}

//打开查看页面
function view(sessionId){
	//alert(sessionId);
	window.location.href= ctx+spaceDomain+objName+"/view?sessionId="+sessionId;
}

//查询提交
function myListSearch(){
	searchSubmit(objName,"myList");
}

//===================新增===================
//新增： 打开新增窗口
function addOPen(){
	$("#add_window").dialog('open');
	$("#addButton").show();
	$("#editButton").hide();
}

//新增一条记录
function add(){
	setMyTime('openTime');
    var smode = $('#sessionMode').combobox('getValue');//var smode = $('#addForm').find("input[name='sessionMode'][type='hidden']").val();
    if(smode==""||smode==null){//direction的关联赋值在数据字典初始化的回调方法中
       alert("竞价方式不能为空！");
       return;
    }
    if(smode=="1" || smode=="3" || smode=="5" || smode=="7"){
    	$('#addForm').find("input[name='direction']").val("T");
    }else{
    	$('#addForm').find("input[name='direction']").val("F");
    }
    //var bj = $('#bjServerStr').combobox('getValue');//var bj = $('#addForm').find("input[name='bjServerStr'][type='hidden']").val();
    var bj = $('#bjServerStr').val();
    if(bj==""||bj==null){
       alert("报价服务器不能为空！");
       return;
    }
    var limitTime = $('#limitTime').val();
	if(limitTime == 0){
		alert("限时报价周期值不能为0！");
		return;
	}
    var firstTime = $('#firstTime').val();
	if(firstTime == 0){
		alert("自由报价期值不能为空或0！");
		return;
	}
	addSubmit(objName,'addForm');	
}
//新增后回调方法
function addCallBack(flag,msg,objName){
	if(flag=="T"){
		myListSearch();
	}else{
		alert(msg);
	}
	$("#add_window").dialog('close');
	
}

//===================更新===================
//打开更新页面
function editOpen(objId){
    clearFormById("addForm");
    //本业务系统下拉数据
	//jsonDataSelect("bjServerStr","server","");
	jsonDataSelectAjax("bjServerStr","server");
	currentObjId=objId;
	getObj(objName,objId);
	$("#addButton").hide();
	$("#editButton").show();
}

function getCallBack(flag,obj){
	if("T"==flag){
		loadData(obj,"addForm");//此方法对combobox不起作用，故下面单独处理
		$('#sessionMode').combobox('setValue',(obj.sessionMode==null||obj.sessionMode==undefined)?"":obj.sessionMode);
		$('#bjServerStr').combobox('setValue',(obj.spare5==null||obj.spare5==undefined)?"":obj.spare5);
		
		//反显图片
		if(obj!=null && obj.spare3!=undefined && obj.spare3!=null && obj.spare3!=''){
			$("#fileUpText_1_showImg").attr("src",obj.spare3);			
		}
		
		$("#add_window").dialog('open');
	}else{
		alert("查询失败");
	}
}

//更新提交
function edit(){
 editSubmit(objName,currentObjId,"addForm");
}
//更新后回调方法
function editCallBack(flag,objName){
	if(flag=="T"){
		myListSearch();
		clearFormById("addForm");
		$("#add_window").dialog('close');
	}else{
		alert("更新失败！");
	}
	
}

//===================删除===================
//删除
function del(objId){
	if(confirm("确定要删除吗？")){
		delSubmit(objName,objId);
	}
}
//删除后回调方法
function delCallBack(flag,objName){
	if(flag=="T"){
		myListSearch();
	}else{
		alert("删除失败！");
	}
}


function loadDiceOneStep(firstId,cateEname,fatherValue,ctx,callBack) {
	$('#'+firstId).combobox({
		url : ctx+'/dict.do?cateEname='+cateEname+'&fatherValue='+fatherValue,
		value:'1',
		valueField : 'id',
		editable : false,
		textField : 'text',
		onSelect:function(rec){
			if(callBack != null && callBack != ""){
				changeMode(rec.id);
			}
		}
	});
}

function changeMode(bmode){
	//alert(bmode);
	bidMode = bmode;
	if(bidMode=="3" || bidMode=="4"){		
		$("#limitTime").val('60');
		$("#limitTimeTr").hide();
	}else{
		$("#limitTime").val('60');
		$("#limitTimeTr").show();
	}
	
}

//==========================================
//初始化加载
$(function(){
	//加载分页列表
	myListSearch();
	createMyTimeOption('openTime');
	var nowd = getNowFormatDate();
	initMyTime('openTime',nowd);
	 //数据字典：竞价方式企业经济类型[firstId="jjlx",secondId="city",cateEname="cty",fatherValue="0"(顶级为0),ctx="${ctx}"]
	loadDiceOneStep('sessionMode','bidMode',0,'${ctx}','changeMode');
	$("#sessionMode").combobox("setValue","1");//初始值“---请选择---”被clear掉了，所以需要加此行代码
	/**var tmp = $('#jjlxFir').combobox('getValue');
	loadSecondStep('jjlxSec','jjlx',tmp,'${ctx}');
	**/
	jsonDataSelectAjax("bjServerStr","server");
});

//附件上传回调方法
function myBack(){
	
}
//串行联动控制
function line(flag){
	if("T"==flag){
		//串行，显示自由报价期、限时报价周期、休息时长
		//$("#tr_zybjq").show();
		$("#tr_xxsc").show();
	}else{
		//$("#tr_zybjq").hide();
		$("#tr_xxsc").hide();
	}
}
</script>

